package com.scitc.pleasurevideo.data;

import android.text.TextUtils;

import com.scitc.pleasurevideo.pojo.UserVo;
import com.scitc.pleasurevideo.util.ConstUtil;
import com.scitc.pleasurevideo.util.ReflectionUtil;
import com.scitc.pleasurevideo.x5webview.MyApplication;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserDataMan {

    private static UserDataMan userDataMan;

    public static synchronized UserDataMan init(){
        if(userDataMan==null){
            userDataMan=new UserDataMan();
        }
        return userDataMan;
    }

    /**
     * 获取用户
     * @return
     */
    public UserVo getUser(){
        String json=ETMan.getPref(MyApplication.getInstance(), ConstUtil.USER_JSON,"");
        if(TextUtils.isEmpty(json)||json.length()<1){
            return null;
        }
        return ETMan.getMananger().getGson().fromJson(json,UserVo.class);
    }

    /**
     * 保存用户
     * @param vo
     */
    public void saveUser(UserVo vo){
        String json=ETMan.getMananger().getGson().toJson(vo);
        ETMan.savePref(MyApplication.getInstance(), ConstUtil.USER_JSON,json);
    }

    /**
     * 保存用户
     * @param json
     */
   public void saveUser(String json){
        ETMan.savePref(MyApplication.getInstance(), ConstUtil.USER_JSON,json);
    }
    /**
     * 判断有没有用户
     * @return
     */
    public boolean isUserLogin(){
        UserVo userVo=getUser();
        if(userVo==null){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 退出登录
     */
    public void exitUser(){
        ETMan.savePref(MyApplication.getInstance(), ConstUtil.USER_JSON,"");
    }

}
